package bb.lanxing.fragment.routebook;

import com.baidu.mapapi.model.LatLng;

import java.util.List;

import bb.lanxing.App;
import bb.lanxing.R;
import bb.lanxing.manager.SharedManager;
import bb.lanxing.model.database.RouteBook;
import bb.lanxing.model.database.Province;
import bb.lanxing.model.database.User;
import bb.lanxing.network.RxJavaHttpClient;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;

public class RecommendRouteBookListFragment extends RouteBookListFragmentNew {
    @Override
    public void requestData() {
        loadData(true);
    }


    @Override
    protected void loadMoreEvent() {
        loadData(false);
    }

    private void loadData(final boolean bPullDown) {
        if (bPullDown) {
            resetPage();
        }
        LatLng curLatLngWithMP = SharedManager.getInstance().getCurLatLngWithMP();
        User signinUser = App.getContext().getSigninUser();
        long j = 0;
        if (signinUser != null) {
            String province = signinUser.getProvince();
            if (Province.getCount() <= 0) {
                Province.importDatas();
            }
            j = Province.getProvinceIdByName(province);
        }
        RxJavaHttpClient.requestLushuRecommendtionList(0, getPage(), getPageSize(), curLatLngWithMP.latitude, curLatLngWithMP.longitude, j).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                refreshComplete();
            }

            @Override
            public void onNext(List<RouteBook> recommendedRouteBook) {
                refreshUIWithServer(recommendedRouteBook, bPullDown);
            }
        });
    }

}